package com.igeek.clud_system.service;

import com.igeek.clud_system.dao.ClubMemberDao;
import com.igeek.clud_system.dao.ClubMembershipRequestDao;
import com.igeek.clud_system.dao.StudentDao;
import com.igeek.clud_system.entity.ClubMembers;
import com.igeek.clud_system.entity.ClubMembershipRequests;
import com.igeek.clud_system.entity.Student;
import com.igeek.clud_system.pojo.Goby;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ClubRequestService {
    @Autowired
    ClubMemberDao clubMemberDao;

    @Autowired
    ClubMembershipRequestDao requestDao;

    @Autowired
    StudentDao studentDao;

    /**
     * 判断是否为社团成员
     */
    public List<ClubMembers> findMembers(Integer clubId, Integer studentId){
        return clubMemberDao.findClubMem(clubId,studentId);
    }

    /**
     * 判断是否已发申请
     */
    public ClubMembershipRequests findRequest(Integer studentId,Integer clubId){
        ClubMembershipRequests request = requestDao.findRequest(studentId, clubId);
        return request;
    }

    /**
     * 增加加入社团申请
     */
    public void insertRequest(Integer studentId,Integer clubId){
        requestDao.insertToClub(clubId,studentId,new Date());
    }
    /**
     * 判断是否已发退出申请
     */
    public ClubMembershipRequests findRequest2(Integer studentId,Integer clubId){
        ClubMembershipRequests request = requestDao.findRequest2(studentId, clubId);
        return request;
    }

    /**
     * 增加推出社团申请
     */
    public void insertRequest2(Integer studentId,Integer clubId){
        requestDao.insertToClub2(clubId,studentId,new Date());
    }

    /**
     * 获取社团申请
     */
    public List<Goby> getAllRe(Integer clubId){
        List<ClubMembershipRequests> clubAllRequest = requestDao.findClubAllRequest(clubId);
        List<Goby> list = new ArrayList<>();
        for (ClubMembershipRequests clubMembershipRequests : clubAllRequest) {
            Student studentById = studentDao.findStudentById(clubMembershipRequests.getStudentId());
            Goby goby = new Goby();
            goby.setClubMembershipRequests(clubMembershipRequests);
            goby.setStudent(studentById);
            list.add(goby);
        }
        return list;
    }
}
